﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Debug = System.Diagnostics.Debug;
using Microsoft.Xna.Framework.Content;

namespace XNADota.Terrain
{
    public class VertexInfo
    {
        public float GroundHeight;
        public Vector3 Position; // 2 bytes
        public int WaterLevel;   // 2 bytes
        public byte Flags; // 0.5 byte
        public byte TextureId; // 0.5 byte
        public byte TextureDetail; // 1 byte
        public byte CliffTextureType; // 0.5 byte
        public byte LayerHeight; // 0.5 byte

        // Data 
        private static int _DebugVertexInfoId = 0;

        private int _DebugId;

        private bool[] _SurfaceVisible = {true, true, true, true};  // A surface is invisible if four points are all invisible
        [ContentSerializerIgnore]
        public bool[] SurfaceVisible
        {
            get { return _SurfaceVisible; }
            set { _SurfaceVisible = value; }
        }

        public bool IsRampPoint
        {
            get { return Convert.ToBoolean(Flags & 1); }
        }

        private VertexInfo()
        {
            _DebugId = _DebugVertexInfoId;
            _DebugVertexInfoId++;
        }

        private int _PrintCount = 0;
        public void PrintDebugInfo()
        {
            Debug.Write(" Count " + _PrintCount + "   ");
            Debug.Write(" X " + _DebugId % 129 + "   ");
            Debug.Write(" Y " + _DebugId / 129 + "   ");
            Debug.Write(" ID " + _DebugId);
            Debug.Write(" Surface Visible " + _SurfaceVisible);

            Debug.WriteLine("");
        }

        public void DebugPrint()
        {
            Debug.WriteLine("Vertex Info");
            Debug.WriteLine(string.Format("{0:x4}", Flags));
            Debug.WriteLine("Texture Id " + TextureId);
            Debug.WriteLine("Texture Detail " + TextureDetail);
        }
    }
}
